<template>
    <div>
        <el-dialog
            v-model="userRoleVisible"
            title="分配角色"
            width="50%"
            :before-close="handleClose"
        >

            <el-transfer :titles="['未分配角色', '已分配角色']" v-model="assignRoles" :data="allRoles" />
            <template #footer>
                <span class="dialog-footer">
                    <el-button @click="userRoleVisible = false">Cancel</el-button>
                    <el-button type="primary" @click="handleAssign">
                        Confirm
                    </el-button>
                </span>
            </template>
        </el-dialog>
    </div>
</template>
<script setup>
import {ref} from 'vue';
import { useUserStore } from '../../stores/user';
import { storeToRefs } from 'pinia';
import { assignRole } from '../../service/user';

const userStore = useUserStore();
const {userId,userRoleVisible,allRoles,assignRoles} = storeToRefs(userStore);

async function handleAssign(){
    await assignRole(userId.value,assignRoles.value);
    userRoleVisible.value = false;
}
</script>
<style scoped></style>
